package com.woniuxy.order.web.controller;


import cn.hutool.core.bean.BeanUtil;
import com.woniuxy.core.model.PageInfo;
import com.woniuxy.core.model.Result;
import com.woniuxy.core.util.JwtUtil;
import com.woniuxy.core.util.RedisUtil;
import com.woniuxy.order.service.OrderCommentService;
import com.woniuxy.order.service.param.CommentOrderParam;
import com.woniuxy.order.web.controller.form.CommentOrderForm;
import io.jsonwebtoken.Claims;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 凌玉春
 * @since 2024年01月15日
 */
@RestController
@RequestMapping("/orderComment")
@Api(tags = "订单评论接口")
public class OrderCommentController {
    @Autowired
    private OrderCommentService orderCommentService;
    @Autowired
    private RedisUtil redisUtil;

    @PostMapping("/commentOrder")
    @ApiOperation("用户评价订单")
    public Result commentOrder(@RequestHeader String token, @RequestBody CommentOrderForm form) throws Exception{
        String longToken = redisUtil.get(token);
        Claims claims = JwtUtil.parseUserToken(longToken);
        Integer id =(Integer) claims.get("id");
        CommentOrderParam param = BeanUtil.toBean(form, CommentOrderParam.class);
        param.setUserInfoId(id);
        orderCommentService.commentOrder(param);
        return Result.getResult().setMessage("评价成功");
    }

}

